<%-- 
功能：显示属性input
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="probiz" tagdir="/WEB-INF/tags/probiz"%>

<%@tag import="com.probiz.estore.common.model.customer.Customer"%>
<%@tag import="com.probiz.estore.common.model.content.Content"%>
<%@tag import="com.probiz.estore.common.model.product.Product"%>
<%@ attribute name="attribute" required="true" description="en entity of Attribute in any of the scope" type="com.probiz.estore.common.model.attribute.Attribute"%>
<%@ attribute name="entity" description="one entity of Product、Customer、Content、Category、Salesorder" type="java.lang.Object" %>
<%@ attribute name="isdisplayHelp" description="setting the value of this attribute to 'true' to display a div content ico" type="java.lang.Boolean"%>
<%@ attribute name="cssName" type="java.lang.String" description="input类型的css"%>
<%@ attribute name="cssStyle" type="java.lang.String" description="样式"%>
<%@ attribute name="id" type="java.lang.String" description="可以通过此ID来获取该元素" %>



<%
if(entity != null){
   if(entity instanceof Customer){
       Customer value = (Customer) entity;
       request.setAttribute("attrValueSet",value.getCustomerAttrValues());
   }
   else if(entity instanceof Content){
       Content value = (Content) entity;
       //request.setAttribute("attrValueSet",value.getContentAttrValues());
   }
   else if(entity instanceof Product){
       Product value = (Product) entity;
       request.setAttribute("attrValueSet",value.getProductAttrValues());
   }
}   
%>

<c:if test="${not empty entity}">
<c:forEach var="attr_value_set"  items="${attrValueSet}">
  <c:if test="${attr_value_set.attributeId eq attribute.attributeId}">
       <c:set var="attr_value" value="${attr_value_set.attributeValue}"/>
       <c:set var="attr_name" value="probizAttr--${attribute.attributeCode}__${attribute.attributeType }__${attribute.attributeDataType }"/>
  </c:if>
</c:forEach>
</c:if>

<c:if test="${not empty id}">
   <c:set var="aid" value="${id}"/>
</c:if>
<c:if test="${empty id}">
   <c:set var="aid" value="${attribute.attributeCode }_id"/>
</c:if>



<c:if test="${empty attr_name}">
<c:set var="attr_name" value="probizAttr--${attribute.attributeCode}__${attribute.attributeType }__${attribute.attributeDataType }"/>
</c:if>

<c:set var="default_value" value="${attribute.defaultValue}"/>

<c:choose>
  <c:when test="${attribute.attributeDataType == 1}">
     <c:set var="array" value='${fn:split(default_value,",")}'/>
     <c:set var="value_array" value='${fn:split(attr_value,",")}'/>
     <c:forEach var="item0" items="${array}" varStatus="status">
         <input value="${item0 }" type="checkbox" id="${aid}_${status.index}"
          <c:forEach var="v" items="${value_array }">
             <c:if test="${v eq item0 }">checked="checked"</c:if>
          </c:forEach>
          <c:if test="${not empty cssName }">class="${cssName }"</c:if> name="${attr_name }" <c:if test="${attribute.isRequired == 1}">validConf="required"</c:if>/>
          <label for="${aid}_${status.index}"> <c:out value="${item0}"/>&nbsp;</label>
          <input type="hidden" value="" name="_${attr_name }"/>
     </c:forEach>
  </c:when>

  <c:when test="${attribute.attributeDataType == 2}">
       <input type="text" id="${aid}" <c:if test="${not empty cssName }">class="${cssName}"</c:if> name="${attr_name }" 
       	<c:if test="${not empty cssStyle}">style="${cssStyle}"</c:if> 
       	value="<c:out value="${attr_value==null?default_value:attr_value }"></c:out>"
        validConf="<c:if test="${attribute.isRequired == 1}">required,</c:if>url"
        />
  </c:when>
  
  
  
  <c:when test="${attribute.attributeDataType == 3}">
	 <script>
         function attrfn_${aid}(path){
            $("aimg_${aid}").src="${mediaPath}"+path;
         }
        </script>
       <img width="58px" heigth="58px" id="aimg_${aid}" src="${mediaPath}${attr_value==null?default_value:attr_value}" border="0" onerror="this.src=__defaultImage_s0;this.onerror='';"/>
       <input type="hidden" id="${aid }" name="${attr_name }" value="<c:out value="${attr_value==null?default_value:attr_value }"></c:out>"
         validConf="<c:if test='${attribute.isRequired == 1}'>required</c:if>"/>
         <probiz:plugin_upload fileInputId="${aid}" onComplete="attrfn_${aid}"/>
        
  </c:when>
  
  
  <c:when test="${attribute.attributeDataType == 4}">
      <input type="text" id="${aid}" <c:if test="${not empty cssName }">class="${cssName }"</c:if> name="${attr_name }" 
      	 <c:if test="${not empty cssStyle}">style="${cssStyle}"</c:if>
         value="<c:out value="${attr_value==null?default_value:attr_value }"></c:out>"
         validConf="<c:if test="${attribute.isRequired == 1}">required,</c:if>integer"
       />
  </c:when>
  
  
  
  <c:when test="${attribute.attributeDataType == 5}">
     <input type="text" id="${aid}" <c:if test="${not empty cssName }">class="${cssName }"</c:if> name="${attr_name }" 
       <c:if test="${not empty cssStyle}">style="${cssStyle}"</c:if>
       value="<c:out value="${attr_value==null?default_value:attr_value }"></c:out>"
       validConf="<c:if test="${attribute.isRequired == 1}">required,</c:if>double"
     />
  </c:when>
  
  
  
  <c:when test="${attribute.attributeDataType == 6}">
     <input type="checkbox" id="${aid}"
     <c:if test="${(attr_value==null?default_value:attr_value) == '1' }">checked="checked"</c:if>
      <c:if test="${not empty cssName }">class="${cssName }"</c:if> name="${attr_name}"/>&nbsp;
     
     <input type="hidden" value="${attr_value==null?default_value:attr_value}" name="_${attr_name}"/>
  </c:when>
  
  
  
  <c:when test="${attribute.attributeDataType == 7}">
     <input name="${attr_name }" id="${aid}" <c:if test="${not empty cssName }">class="${cssName }"</c:if> 
      <c:if test="${not empty cssStyle}">style="${cssStyle}"</c:if>
      value="<c:out value="${attr_value==null?default_value:attr_value }"></c:out>" type="text"
      validConf="date<c:if test="${attribute.isRequired == 1}">,required</c:if>">    
     <probiz:ui_datePicker outPut="${aid}" />  
  </c:when>    

  
  
  
  
  <c:when test="${attribute.attributeDataType == 8}">
     <c:set var="array" value='${fn:split(default_value,",")}'/>
     <c:set var="value_array" value='${fn:split(attr_value,",")}'/>
     <c:if test=""></c:if>
     <select name="${attr_name }" id="${aid}" <c:if test="${not empty cssName }">class="${cssName }"</c:if>
     	<c:if test="${not empty cssStyle}">style="${cssStyle}"</c:if> 
       <c:if test="${attribute.isRequired == 1 }">validConf="required"</c:if>>
       <option value=""><fmt:message key="form.select.all"/> </option>
       <c:forEach var="item0" items="${array}">
             <option
             <c:forEach var="item1" items="${value_array }">
              <c:if test="${item1 eq item0}">selected="selected"</c:if>
              </c:forEach>
             value="${item0}">${item0}</option>
       </c:forEach>
     </select>
  </c:when>
  
  <c:when test="${attribute.attributeDataType == 9}">
     <c:set var="array" value='${fn:split(default_value,",")}'/>
     <c:set var="value_array" value='${fn:split(attr_value,",")}'/>
     <c:forEach var="item1" items="${array}" varStatus="status">
        <input id="${aid}_${status.index}"
           <c:forEach var="item0" items="${value_array }">
             <c:if test="${item0 eq item1 }">checked="checked"</c:if>
           </c:forEach>
         name="${attr_name}" <c:if test="${not empty cssName }">class="${cssName }"</c:if> value="${item1}" type="radio"
           <c:if test="${attribute.isRequired == 1 }">validConf="required"</c:if>
        /><label for="${aid}_${status.index}">${item1 }&nbsp;</label>
     </c:forEach>
  
  </c:when>
  
  
  
  
  <c:when test="${attribute.attributeDataType == 10}">
      <input type="text" id="${aid}" <c:if test="${not empty cssName }">class="${cssName}"</c:if> 
      	<c:if test="${not empty cssStyle}">style="${cssStyle}"</c:if>
        name="${attr_name }" value="<c:out value="${attr_value==null?default_value:attr_value }"></c:out>"
        validConf="<c:if test="${attribute.isRequired == 1}">required,</c:if>maxlength=36"
       />
  </c:when>
  
  
  
  <c:otherwise>
      <textarea name="${attr_name }" id="${aid}" <c:if test="${not empty cssName }">class="${cssName}"</c:if>
      	<c:if test="${not empty cssStyle}">style="${cssStyle}"</c:if>
        <c:if test="${attribute.isRequired == 1 }">validConf="required"</c:if> ><c:out value="${attr_value==null?default_value:attr_value }"></c:out></textarea>
  </c:otherwise>
  
  
  
  
</c:choose>

<c:if test="${isdisplayHelp and ! empty attribute.description}">
      <probiz:plugin_tip id="${aid}_tip" type="help">${attribute.description}</probiz:plugin_tip>
</c:if>
    
